package 笔试;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class 小米_手机运行时常 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = null;
        String[] ss = new String[1000];
        int count1 = 0;
        int k = 0;
        while (true) {
            s = scan.nextLine();
            if(s.equals("")) {
                break;
            } else {
                ss[k] = s;
                k++;
            }
            count1++;
        }

        int n = count1;
        int[][] intervals = new int[n][2];

        for (int i = 0; i < n; i++) {
            String[] tmp = ss[i].split(" ");
            intervals[i][0] = Integer.parseInt(tmp[0]);
            intervals[i][1] = Integer.parseInt(tmp[1]);
        }
        Arrays.sort(intervals, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] - o2[0];
            }
        });
        int count = 0;
        for (int i = 0; i < n; i++) {
            if(i == 0) {
                count = intervals[i][1] - intervals[i][0];
            } else  if(intervals[i][0] < intervals[i-1][1]) {
                count += intervals[i][1] - intervals[i-1][1];
            } else if(intervals[i][0] > intervals[i-1][1]) {
                count += intervals[i][1] - intervals[i][0];
            }
        }
        System.out.println(count);
        System.exit(0);
    }
}
